<?php
class Admin_IndexController extends Admin_Library_Controller_Action_Abstract
{
	public function indexAction()
	{
	}
	public function loginAction()
	{
		$identity = Zend_Auth::getInstance()->hasIdentity();
        if (FALSE === $identity) {
            $loginForm = new Admin_Form_LoginForm();
            if ($this->getRequest()->isPost()) {
                $data = $this->getRequest()->getPost();
                if ($loginForm->isValid($data)) {
                    $data = array_merge($data, $loginForm->getValues());
                    $adminRepository = new Mkk_Model_AdminRepository();
                    $result = $adminRepository->login($data['loginName'], $data['password']);
                    if ($result == TRUE) {
                        $this->_redirect('/admin');
                    } else {
                        $this->view->messages['error'][] = "ADM-01_username_or_password_is_incorrect";
                    }
                } else {
                    $this->view->messages['error'][] = "ADM-01_username_or_password_is_incorrect";
                }
            }
        } else {
            $this->_redirect('/admin');
        }
        $this->view->form = $loginForm;
        $this->render("login");
	} 
}